<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#--引入外部文件-->
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大攻略管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
            </form>
            <a href="javascript:" class="btn btn-success inputBtn">
                <span class="glyphicon glyphicon-plus"></span> 添加
            </a>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>地区</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#--使用Freemark的指令完成循环迭代-->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${entity.coverUrl}" width="30px" /></td>
                        <td>${entity.title}</td>
                        <td>${entity.subTitle}</td>
                        <td>${entity.place.name}</td>
                        <td>
                                <#if entity.state==-1 >
                                   禁用
                                    <#elseif entity.state==0>
                                   正常
                                    <#elseif entity.state==1>
                                    推荐
                                </#if>
                        </td>
                        <td>
                            <a href="javascript:" class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>


<#--模态框必须是body的子元素-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/strategy/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入标题"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">副标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="subTitle" placeholder="请输入副标题"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img  id="coverImg" width="100%"> <!--用来显示-->
                            <input type="hidden" class="form-control" name="coverUrl" /><!--用来提交表单(回显)-->
                            <input type="file" class="form-control" name="file" /><!--用来提交表单(上传)-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">地区：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="place.id">
                                <#list regions as r>
                                    <option value="${r.id}">${r.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">状态：</label>
                        <div class="col-lg-6">
                            <select name="state" class="form-control">
                                <option value="-1">禁用</option>
                                <option value="0">正常</option>
                                <option value="1">推荐</option>
                            </select>
                        </div>
                    </div>

                </form>

            </div>
            <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".inputBtn").click(function () {
            //1:先清空模态框的数据,再来做操作
            $("#inputModal input").val("");
            //2:获取当前按钮中的自定义JSON对象
            var obj = $(this).data("json");
            //3:只有编辑按钮才做数据回显
            if (obj) {
                $("#inputModal input[name='id']").val(obj.id);
                $("#inputModal input[name='title']").val(obj.title);
                $("#inputModal input[name='subTitle']").val(obj.subTitle);
                $("#inputModal select[name='place.id']").val(obj.placeId);
                $("#inputModal select[name='state']").val(obj.state);
                $("#inputModal input[name='coverUrl']").val(obj.coverUrl);
                $("#coverImg").attr('src',obj.coverUrl);
            }
            $("#inputModal").modal('show');
        })
        
    })
</script>

</body>
</html>